#include "fdt_vector.h"
#include <stdio.h>
#include <unistd.h>

struct pixel_t {
    int r;
    int g;
    int b;
};

static struct fdt_vector image = {
    .name = "fdt_pixel_vector",
    .obj_size = sizeof(struct pixel_t),
    .size = 256
};

int main()
{
    fdt_vector_create(&image);

    struct pixel_t* pixel, *pos;
    int index = 12;

    /*
     * pos & pixel will point to same shared memory location
     */
    pixel = fdt_get_ptr(&image, pos, index);
    pixel->r = 128;
    pixel->g = 64;
    pixel->b = 64;
    fdt_put_ptr(&image, index);

    //..
    index = 36;

    pixel = fdt_try_get_ptr(&image, pos, index);
    if (pixel != NULL) {
        pixel->r = 23;
        pixel->g = 68;
        pixel->b = 32;        
        fdt_put_ptr(&image, index);
    }

    fdt_vector_destory(&image);

    return 0;
}
